package com.gkey.demo.task;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.core.task.TaskExecutor;
import org.springframework.stereotype.Service;

@Service
public class ExecutorExampleImpl implements ExecutorExample {

	private Logger logger = Logger.getLogger(ExecutorExampleImpl.class);

	// 执行器
	@Resource
	private TaskExecutor taskExecutor;

	@Resource
	private TaskService taskService;

	@Override
	public void exce() {
		//logger.debug("[Thread " + Thread.currentThread().getId() + " start]");
		taskExecutor.execute(new Runnable() {
			@Override
			public void run() {
				System.out.println("Astart:"+System.currentTimeMillis());
				for (int i = 0; i < 100; i++) {
					System.out.println("A:" + i);
				}
				System.out.println("Aend:"+System.currentTimeMillis());
			}
		});
		taskExecutor.execute(new Runnable() {
			@Override
			public void run() {
				System.out.println("Bstart:"+System.currentTimeMillis());
				for (int i = 0; i < 100; i++) {
					System.out.println("B:" + i);
				}
				System.out.println("Bend:"+System.currentTimeMillis());
			}
		});
		//logger.debug("[Thread " + Thread.currentThread().getId() + " end]");
	}

}
